package com.maps;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;


import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.service.WebService;


public class CircularItemizedOverlay extends ItemizedOverlay {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	public CircularItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}
	
	public CircularItemizedOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}

	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
		
		OverlayItem origItem = mOverlays.get(0);
	  OverlayItem destItem = mOverlays.get(index);
	  GeoPoint pointUser = origItem.getPoint();
	  GeoPoint pointDest = destItem.getPoint();
	  
	  //WebService serv = new WebService("");
	  //travelduration = serv.getTempoViagem(pointUser, pointDest);
	  
	  new WebService(mContext, destItem).execute(pointUser, pointDest);
	  /*
	  String travelduration = DirectionsCalls.getInstance().
	  	getTravelDuration(String.valueOf(pointUser.getLatitudeE6() / 1E6), 
	  						String.valueOf(pointUser.getLongitudeE6() / 1E6),
	  						String.valueOf(pointDest.getLatitudeE6() / 1E6),
	  						String.valueOf(pointDest.getLongitudeE6() / 1E6));
	  */
	  
	  
		
	  return true;
	}

}
